#!/bin/bash

pkg1() {
    echo "安装 adb"
    echo "下载软件压缩包...(Gitee源)"
    wget -qO PKG "https://gitee.com/bedlock/pkg/releases/download/adb/adb.tar.gz"
    echo '解压软件压缩包'
    tar -xvzf PKG -C "$PREFIX"
    echo '删除临时文件'
    rm -rf PKG
    echo '给予软件包权限'
    chmod -R 777 "$PREFIX"
}

options=("ADB" "退出")
commands=("pkg1" "exit")

selected=0

clear_screen() {
    clear
    echo -e "LWF快速安装---------------\n"
    for i in "${!options[@]}"; do
        if ((selected == i)); then
            echo -e ">> \e[1;44m ${options[$i]} \e[0m"
        else
            echo " ${options[$i]} "
        fi
    done
    echo -e "\n--------------------------"
}

execute_command() {
    if ((selected == ${#options[@]} - 1)); then
        exit 0
    else
        eval "${commands[$selected]}"
        echo "按任意键继续..."
        read -rsn1
        clear_screen
    fi
}

clear_screen

while true; do
    echo -e "\e[33;1m按住方向键上下或A和B选择，回车确定\e[0m"
    read -rsn1 key
    case "$key" in
        "A")
            ((selected > 0)) && ((selected--))
            ;;
        "B")
            ((selected < ${#options[@]} - 1)) && ((selected++))
            ;;
        "")
            execute_command
            ;;
    esac
    clear_screen
done